﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using BenevolentSunData;

namespace BenevolentSun
{
    class Hud
    {

        public TextField CellName;

        public TextField CellNote;

        public TextField Time;

        public void SetTime(TimeSpan time)
        {
            String min = time.Minutes.ToString();

            String sec = time.Seconds.ToString();
            if (sec.Length < 2)
                sec = "0" + sec;
            String ms = time.Milliseconds.ToString();
            if (ms.Length < 2)
                ms = "00" + ms;
            else if (ms.Length < 3)
                ms = "0" + ms;
            ms = ms.Substring(0, 2);
            Time.Text = min + ":" + sec + ":" + ms;
        }

        public TextField Stage;

        public TextField StageNumber;


        public Hud(ContentManager content)
        {
            SpriteFont timeFont = content.Load<SpriteFont>("Fonts/EbrimaBold50");
            Time = new TextField("0:0:00", timeFont);
            Time.AlignH = AlignH.Right;
            Time.Position = new Vector2(1280f - 5f, 5f);

            SpriteFont cellNameFont = timeFont;
            CellName = new TextField("", cellNameFont);
            CellName.AlignH = AlignH.Center;
            CellName.Position = new Vector2(1280f / 2f, 5f);

            SpriteFont cellNoteFont = content.Load<SpriteFont>("Fonts/Ebrima30");
            CellNote = new TextField("", cellNoteFont);
            CellNote.AlignH = AlignH.Center;
            CellNote.Position = new Vector2(1280f / 2f, 5f + cellNameFont.MeasureString("I").Y + 5f);

            SpriteFont stageFont = cellNoteFont;
            Stage = new TextField("Stage", stageFont);
            Stage.AlignH = AlignH.Right;
            Stage.AlignV = AlignV.Top;
            Stage.Position = new Vector2(1280f - 5f - 5f, 720f - 5f);

            SpriteFont stageNumberFont = timeFont;
            StageNumber = new TextField("", stageNumberFont);
            StageNumber.AlignH = AlignH.Right;
            StageNumber.AlignV = AlignV.Top;
            StageNumber.Position = new Vector2(1280f - 5f, 720f - 5f);
        }


        public void Update(GameTime gameTime)
        {
            
        }


        public void Draw(SpriteBatch spriteBatch)
        {
            Time.Draw(spriteBatch);

            CellName.Draw(spriteBatch);

            CellNote.Draw(spriteBatch);

            Stage.Position.X = StageNumber.Position.X - StageNumber.TextDimensions.X - 10f;
            Stage.Draw(spriteBatch);

            StageNumber.Draw(spriteBatch);
        }

    }
}
